<template>
  <div class="person">
    <h2>情况五：监视上述多个数据</h2>
    <h2>姓名：{{ person.name }}</h2>
    <h2>年龄：{{ person.age }}</h2>
    <h2>汽车：{{ person.car.c1 }}----{{ person.car.c2 }}</h2>
    <button @click="handleName">修改姓名</button>
    <button @click="handleAge">修改年龄</button>
    <button @click="handleC1">修改车1</button>
    <button @click="handleC2">修改车2</button>
    <button @click="handlePer">修改整个人</button>
    <button @click="handleCar">修改整个车</button>
  </div>
</template>
  <script setup lang='ts'>
import { reactive, watch } from "vue";
let person = reactive({
  name: "张三",
  age: 18,
  car: {
    c1: "奔驰",
    c2: "宝马"
  }
});
function handleName() {
  person.name += "~";
}
function handleAge() {
  person.age += 1;
}
function handleC1() {
  person.car.c1 = "奥迪";
}
function handleC2() {
  person.car.c2 = "大众";
}
function handlePer() {
  // person = Object.assign(person,{name:"历史",age:123});
  //或者
  Object.assign(person, { name: "历史", age: 123 });
}
function handleCar() {
  person.car = { c1: "雅达", c2: "新日" };
}
//监听：情况五，监视多个数据
watch(
  [() => person.name, () => person.car.c1],
  (newV, oldV) => {
    console.log("person-----name和car变化了", newV, oldV);
  },
  { deep: true }
);
</script>
  <style scoped>
.person {
  background-color: skyblue;
  box-shadow: 0 0 10px;
  border-radius: 10px;
  padding: 20px;
}
</style>